package com.cyc.basic.controller;

import com.cyc.basic.util.ConsistentAlgorithm;
import com.cyc.common.exception.BaseException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @description:
 * @version 1.0
 * @author cyc
 * @date 2021/12/11 15:52
 */
@Api(tags = "猎聘工具")
@RestController
@RequestMapping(value = "liepin")
public class LiePinController {

    @GetMapping("/getDbTableIndex")
    @ApiOperation("根据分表键获取桶索引和表索引")
    public String getDbTableIndex(String shardId) {
        int[] dbIndexAndTableIndex = ConsistentAlgorithm.hash(shardId);
        if (dbIndexAndTableIndex.length < 2) {
            throw new BaseException("400", "桶索引或表索引为空");
        }
        return "桶索引: " + dbIndexAndTableIndex[0] + ", 表索引: " + dbIndexAndTableIndex[1];
    }
}
